<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html" import="java.util.Collection, Bean.*"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%>
<%
if(session.getAttribute("un")==null){
    response.sendRedirect("indexAdmin.jsp?page=Admin&url=Login");
    out.println("You must be login..!");
}else{%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<script language="javascript" type="text/javascript" src="../script/validate.js"></script>
<script language="javascript">
       function kiemtra(){
        var id = document.form1.subid;
        var name = document.form1.subname;
        if( laChuoiRong(id.value))
            {
                alert('Subject ID is not blank!');
                id.focus();
                return false;
            }
        if( laChuoiRong(name.value))
            {
                alert('Subject name is not blank!');
                name.focus();
                return false;
            }    
       }
</script>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <%        
    String id="";String name="";
    if(session.getAttribute("subid")!=null){
        id=session.getAttribute("subid").toString();
        name=session.getAttribute("Sname").toString();
    }
    %>
    <h3 align="center">Subject Management</h3>
    <form action="../ControllSubject" method="post" name="form1" onsubmit="return kiemtra()">
        <table>
            <tr>
                <td>SubID:</td>
                <td><input type="text" name="subid" value="<%=id%>" /><input type="hidden" name="tempsubid" value="<%=id%>" /></td>
            </tr>
            <tr>
                <td>SemID:</td>
                <td>
                    <select name="semid">
                        <option value="Sem1">HKI</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>SubName:</td>
                <td><input type="text" name="subname" value="<%=name%>" /></td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" name="bt" value="Insert" />
                    <input type="submit" name="bt" value="Update" />
                    <input type="button" name="btreset" value="Reset" onclick="clear_fields()" />
                </td>
            </tr>
        </table>
    </form>
    <%
    SubjectBean subject=new SubjectBean();
    Collection kq1=subject.getListSubject();
    request.setAttribute("st", kq1);
    %>
    <table border="1">
        <tr>
            <th>Subid</th>
            <th>Semid</th>
            <th>SubName</th>
            <th colspan="2">Action</th>
        </tr>
        <c:forEach items="${st}" var="s">
            <tr>
                <td><c:out value="${s.subID}" /></td>
                <td>${s.semID}</td>
                <td>${s.subName}</td>
                <c:url var="delete" value="../ControllSubject">
                    <c:param name="bt" value="Delete" />
                    <c:param name="subid" value="${s.subID}" />
                </c:url>
                <c:url var="edit" value="../ControllSubject">
                    <c:param name="bt" value="Edit" />
                    <c:param name="subid" value="${s.subID}" />
                    <c:param name="subName" value="${s.subName}" />
                </c:url>
                <% if(session.getAttribute("permission")!=null){
        if(session.getAttribute("permission").equals("Academic")){%>
                <td><a href="${edit}">Edit</a></td>
                <%    
                }
                %>
                <% 
                if(session.getAttribute("permission").equals("Admin")){%>
                <td><a href="${edit}">Edit</a></td>
                <td><a href="${delete}" onclick="return confirm('Do you really want to delete these records ?')">Delete</a></td>
                <%    
                }
                %>
                <%}%>
            </tr>
        </c:forEach>                
    </table>
    </form>
</body>
</html>
<%}%>